//
//  Account.m
//  SenssunLife
//
//  Created by admin on 16/8/31.
//  Copyright © 2016年 Zhongshan Camry Electronic Company Limited. All rights reserved.
//

#import "Account.h"

#define SENAccountTokenKey @"token"
#define SENExpires_inKey @"tokenExpiration"
@implementation Account
+ (instancetype)tokenWithDict:(NSDictionary *)dict
{
    Account *account = [[self alloc] init];
    
    [account setValuesForKeysWithDictionary:dict];
    
    return account;
}

- (void)setTokenExpiration:(int)tokenExpiration
{
    _tokenExpiration = tokenExpiration;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:_token forKey:SENAccountTokenKey];
    [aCoder encodeObject:[NSString stringWithFormat:@"%f",_tokenExpiration + [[NSDate date] timeIntervalSince1970]] forKey:SENExpires_inKey];
//    SSLog(@"encodeObject - %@",[NSString stringWithFormat:@"%d",_tokenExpiration]);
}

// 解档的时候调用：告诉系统哪个属性需要解档，如何解档

- (id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        // 一定要记得赋值
        _token =  [aDecoder decodeObjectForKey:SENAccountTokenKey];
        _tokenExpiration = [[aDecoder decodeObjectForKey:SENExpires_inKey] intValue];
    }
    return self;
}

@end
